home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / icmpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  1.7 KB  |  76 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "netuser.h"
  6. #include "icmp.h"
  7. #include "trace.h"
  8. #include "ip.h"
  9.  
  10. #ifdef TNOS_68K
  11. #define fprintf traceprintf
  12. #endif
  13.  
  14. /* Dump an ICMP header */
  15. void
  16. icmp_dump(fp,bpp,source,dest,check)
  17. FILE *fp;
  18. struct mbuf **bpp;
  19. int32 source,dest;
  20. int check;        /* If 0, bypass checksum verify */
  21. {
  22.     struct icmp icmp;
  23.     int16 csum;
  24.  
  25.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  26.         return;
  27.     csum = cksum(NULLHEADER,*bpp,len_p(*bpp));
  28.     
  29.     ntohicmp(&icmp,bpp);
  30.     
  31.     fprintf(fp,"ICMP: type %s",smsg(Icmptypes,ICMP_TYPES,uchar(icmp.type)));
  32.  
  33.     switch(uchar(icmp.type)){
  34.     case ICMP_DEST_UNREACH:
  35.         fprintf(fp," code %s",smsg(Unreach,NUNREACH,uchar(icmp.code)));
  36.         break;
  37.     case ICMP_REDIRECT:
  38.         fprintf(fp," code %s",smsg(Redirect,NREDIRECT,uchar(icmp.code)));
  39.         fprintf(fp," new gateway %s",inet_ntoa(icmp.args.address));
  40.         break;
  41.     case ICMP_TIME_EXCEED:
  42.         fprintf(fp," code %s",smsg(Exceed,NEXCEED,uchar(icmp.code)));
  43.         break;
  44.     case ICMP_PARAM_PROB:
  45.         fprintf(fp," pointer %u",icmp.args.pointer);
  46.         break;
  47.     case ICMP_ECHO:
  48.     case ICMP_ECHO_REPLY:
  49.     case ICMP_INFO_RQST:
  50.     case ICMP_INFO_REPLY:
  51.     case ICMP_TIMESTAMP:
  52.     case ICMP_TIME_REPLY:
  53.         fprintf(fp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  54.         break;
  55.     }
  56.     if(check && csum != 0){
  57.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  58.     }
  59. #ifdef TNOS_68K
  60.     fprintf (fp, "\n");
  61. #else
  62.     putc('\n',fp);
  63. #endif
  64.     /* Dump the offending IP header, if any */
  65.     switch(icmp.type){
  66.     case ICMP_DEST_UNREACH:
  67.     case ICMP_TIME_EXCEED:
  68.     case ICMP_PARAM_PROB:
  69.     case ICMP_QUENCH:
  70.     case ICMP_REDIRECT:
  71.         fprintf(fp,"Returned ");
  72.         ip_dump(fp,bpp,0);
  73.     }
  74. }
  75.  
  76.